home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr01 / halcn305.zip / TESTSCH2.PAS < prev    next >
Pascal/Delphi Source File  |  1993-07-29  |  4KB  |  125 lines

  1. program TestSch2;
  2. {------------------------------------------------------------------------------
  3.                               DBase Key Field Locator
  4.  
  5.        TESTSCH2.PAS Copyright (c)  Richard F. Griffin
  6.  
  7.        14 July 1993
  8.  
  9.        102 Molded Stone Pl
  10.        Warner Robins, GA  31088
  11.  
  12.        -------------------------------------------------------------
  13.        This program demonstrates how status may be checked while running
  14.        key string searches in dBase files.
  15.  
  16.        This example is an extension of the status reporting example that
  17.        was demonstrated in GSDMO_17.PAS.
  18.  
  19.        If the GSDMO_17.DBF file does not exist, the program will display a
  20.        a message that the file was not found and to run GSDMO_17 to make
  21.        the file.
  22.  
  23.        The program opens a dBase file and will ask for a LASTNAME field
  24.        key to search for.  Enter any portion of the string.  During the
  25.        search, the current record being searched is reported.
  26.  
  27. -------------------------------------------------------------------------------}
  28.  
  29. uses
  30.    GSOB_Var,
  31.    GSOBShel,
  32.    GSXT_Sch,
  33.    SmplStuf,
  34.    CRT,
  35.    DOS;
  36.  
  37. var
  38.    St    : string;
  39.    posn : word;
  40.    fnum : word;
  41.  
  42.    h,m,s,c,h1,m1,s1,c1:word;
  43.    rt : real;
  44.  
  45. {-----------------------------------------------------------------------------}
  46. {$F+}
  47. Procedure UserCaptureStatus(stat1,stat2,stat3 : longint);
  48. begin
  49.    case stat1 of
  50.       StatusStart  : begin
  51.                         GotoXY(1,WhereY);
  52.                         case stat2 of
  53.                             StatusSearch : system.write('[ Search Progress ]');
  54.                          end;
  55.                          Writeln;
  56.                          GotoXY(26,WhereY);
  57.                          system.write('Total Records to Process = ',stat3);
  58.                       end;
  59.       StatusStop    : begin
  60.                          GoToXY(79,WhereY);
  61.                          Writeln;
  62.                          Writeln('Finished');
  63.                       end;
  64.       StatusSearch  : begin
  65.                          GoToXy(1,WhereY);
  66.                          if stat2 mod 10 = 0 then    {every 10th record}
  67.                             system.write('Record Number ',stat2,'  ');
  68.                       end;
  69.    end;
  70. end;
  71. {$F-}
  72. {----------------------------------------------------------------------------}
  73.  
  74. begin
  75.                              {Establish user status capture routine}
  76.    SetStatusCapture(UserCaptureStatus);
  77.  
  78.    ClrScr;
  79.    if not FileExist('GSDMO_01.DBF') then   {Check for the file}
  80.    begin
  81.       writeln('File GSDMO_17.DBF not found.  Run GSDMO_17 to create.');
  82.       halt;
  83.    end;
  84.                        {The 'Real' example starts here}
  85.  
  86.    Select(1);                     {Use record area 1 (the default)}
  87.    Use('GSDMO_17');               {Assign the dBase III file GSDMO_17}
  88.    REPEAT
  89.       write('LASTNAME to search for:');
  90.       readln(St);
  91.       if St <> '' then
  92.       begin
  93.          gettime(h,m,s,c);                {Test the time it takes}
  94.  
  95.          fnum := FieldNo('LASTNAME');
  96.          posn := SearchDBF(St,fnum,true);
  97.          if posn > 0 then                 {Posn = starting position in string}
  98.          begin
  99.             writeln(RecNo,'  ',
  100.                     FieldGet('LASTNAME'),' ',       {Get field images}
  101.                     FieldGet('FIRSTNAME'),'  ',
  102.                     FieldGet('UNIQUEID'));
  103.             writeln(RecNo,' records were searched');
  104.          end
  105.          else
  106.          begin
  107.             writeln('No Match!  ',RecCount,' records were searched');
  108.          end;
  109.  
  110.       {  Report elapsed time  }
  111.  
  112.          gettime(h1,m1,s1,c1);
  113.          if s1 < s then s1 := s1 + 60;
  114.          s := (s*100)+c;
  115.          s1 := (s1*100)+c1;
  116.          rt := s1-s;
  117.          rt := rt/100;
  118.          writeln('Time required to find key was  ',rt:2:2,' seconds.');
  119.       end;
  120.  
  121.    until st = '';
  122.    SetStatusCapture(DefCapStatus);        {Restore default status routine}
  123.    CloseDataBases;                {Close the file}
  124. end.
  125.